#!/usr/bin/env python 
# encoding: utf-8 
# @Author: Jacqueline
# @file: demo2_QQ邮箱多层iframe切换.py
# @time: 2021/2/22 15:39

'''
iframe多标签切换封装

'''
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://mail.qq.com/")
driver.implicitly_wait(10)

# 2.输入账号密码，点击登录
# 2.0 点击切换到登录iframe
driver.switch_to.frame('login_frame')
# 2.1 点击账号密码登录
driver.find_element_by_id('swicther_plogin').click()
# 2.2 定位账号输入框，输入账号
driver.find_element_by_id('u').send_keys("577369560@qq.com")
# 2.3 定位密码输入密码
driver.find_element_by_id('p').send_keys("huodaolinli25")
# 2.4 点击登录
driver.find_element_by_id('login_button').click()

# 3.切换到滑块验证码的iframe，点击滑动按钮
# 3.1 切换到滑动验证码的iframe中
tcaptcha = driver.find_element_by_id('tcaptcha_iframe')
driver.switch_to.frame(tcaptcha)
# 3.2选择拖动滑块的节点
driver.find_element_by_id('tcaptcha_drag_thumb').click()


# ——————————————从iframe标签切换到原网页————————
driver.switch_to.default_content()
driver.find_element_by_xpath('//a[text()="基础版"]').click()


#————————————————切换到上一层iframe，如果只有一层就切到原网页——————————————
driver.switch_to.parent_frame()